function Swiper(el,options = {w:'480px',h:'270px'})
{
    // 保存数据
    this.el = document.querySelector(el)
    this.options = options
    this.t=null
    this.num = 1
    this.init()

}

Swiper.prototype.init = function(){
    this.resetOptions()
    this.start()
    this.pageOver()
}

Swiper.prototype.resetOptions = function(){
    // 设置宽高，没有特意设置就是480*270（原图1980*1080）
    this.el.style.width = this.options.w
    this.el.style.height = this.options.h
}

Swiper.prototype.start = function(){
    // 定时器每隔一秒切换图片
    this.t = setInterval(() => {
        // 定时器，图片名 +1 且 1~6
        this.num++
        if(this.num>6) this.num=1//循环1~6
        this.changeImg(this.num)
    },1000)
}


Swiper.prototype.pageOver = function(){
    // 获取当前li
    let liObjs = this.el.querySelectorAll('ul li')
    // 遍历
    liObjs.forEach((item,i) => {
        // 给item绑定移入事件
        item.onmouseover = () => {
            // 清除定时器
            clearInterval(this.t)
            // 改图片
            this.changeImg(i+1)
            this.num = i+1
            console.log(this.num)
        }
        // 绑定移出事件
        item.onmouseout = () => {
            this.pageOut()
        }
    })
}

Swiper.prototype.pageOut = function(){
    this.start()
}

Swiper.prototype.changeImg = function(num){
    // 修改图片src
    this.el.querySelector('img').src = `./imgs/${num}.jpg`
    // 同步分页器
    this.el.querySelector('ul li.active').className = ''
    this.el.querySelector(`ul li:nth-of-type(${num})`).className = 'active'
    
}

// Swiper.prototype.changeImg = function(num) {
//     // 3 定时器中-修改图片src地址【封装】
//     this.el.querySelector('img').src = `./imgs/${num}.jpg`
//     // 4 定时器中-同步分页器 - 干掉别人、照亮自己【封装】
//     this.el.querySelector('ul li.active').className = ''
//     this.el.querySelector(`ul li:nth-of-type(${num})`).className = 'active'
// }

export default Swiper